#include "BaseMaterial.h"
#include <map>


using namespace std;
using namespace prog3d;


BaseMaterial::BaseMaterial() {
}

BaseMaterial::~BaseMaterial() {
}

void BaseMaterial::path(string nom) {
  _defaultPath=nom;
}

void BaseMaterial::add(std::string n,Material *m) {
  _mat[n]=m;
}

Material *BaseMaterial::material(std::string n) {
  if (_mat.find(n)==_mat.end()) return NULL;
  else
    return (_mat.find(n)->second);
}

void BaseMaterial::add(std::string s,Texture *t) {
  _texture[s]=t;
}

Texture *BaseMaterial::texture(std::string n) {
  if (_texture.find(n)==_texture.end()) {
    cout << "load texture " << __FILE__ << n << endl;
    Texture *res=new Texture(_defaultPath+n);
    res->filterLinear();
    _texture[n]=res;
//    cout << "Texture " << n << " read" << endl;
    return res;
  }
  else {
//      cout << "Texture " << n << " already read = " << _texture.find(n)->second <<  endl;
     return (_texture.find(n)->second);
  }
}


